package shun.demo.binder;

import android.content.Context;
import android.graphics.PixelFormat;
import android.os.IBinder;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;

/**
 * Created by chen on 3/18/14.
 */
public class FloatWindow {

    private View mView;
    private IBinder mToken;
    private WindowManager mWindowManager;

    public FloatWindow(Context context, View view, IBinder token) {
        mView = view;
        mToken = token;
        mWindowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    }

    public void show() {
        WindowManager.LayoutParams params = new WindowManager.LayoutParams(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
        params.width = ViewGroup.LayoutParams.WRAP_CONTENT;
        params.height = ViewGroup.LayoutParams.WRAP_CONTENT;
        params.format = PixelFormat.RGBA_8888;
        params.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
//        params.token = mToken;
        mWindowManager.addView(mView, params);
    }

    public void dismiss() {
        mWindowManager.removeView(mView);
    }
}
